import java.util.ArrayList;
import java.util.Scanner;

/**
* Created with IntelliJ IDEA.
* Description:
* User: Gao zhao xu
* Date: 2023-12-11
* Time: 上午 09:45
*/public class Test2 {
    public static void main(String[] args) {
        Scanner input = new Scanner(System.in);
        int n = input.nextInt();
        input.nextLine();
        ArrayList<ArrayList<String>> all = new ArrayList<>();
        for (int i = 0; i < n; i++) {
            String[] arr = input.nextLine().split(" ");
            ArrayList<String> arrayList = new ArrayList<>();
            for (int j = 1; j < arr.length; j++) {
                arrayList.add(arr[j]);
            }
            all.add(arrayList);
        }
        int m = input.nextInt();
        input.nextLine();
        for (int i = 0; i < m; i++) {
            String word = input.nextLine();
            int count = 0;
            for (int j = 1; j <= all.size(); j++) {
                ArrayList<String> arrayList = all.get(j - 1);
                if (arrayList.contains(word)) {
                    count++;
                    System.out.print(j + " ");
                }
            }
            if(count == 0){
                System.out.println("NOT FOUND");
            }else {
                System.out.println();
            }
        }
    }
}
